
# 2-14.通过输入年份和月份，显示指定月份的日历

# 计算当前年份是否为闰年
def leap_year(year):
	if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
		return True
	else:
		return False

# 判断当前月份的天数
def month_days(year, month):
	if month == 2:
		if leap_year(year):
			return 29
		else:
			return 28
	elif month in [1, 3, 5, 7, 8, 10, 12]:
		return 31
	else:
		return 30


#计算从1990年到当前月份的总天数
def total_days_from_1990(year, month):
	sum = 0
	for y in range(1990, year):
		if leap_year(y):
			sum += 366
		else:
			sum += 365
	for m in range(1, month):
		sum += month_days(year, m)
	return sum


# 以1990年1月1日作为星期一进行输出
if __name__ == '__main__':
	year = 2024
	month = 11
	print('\t\t{}年{}月份日历'.format(year, month))
	print('Mon\t Tues\t Wed\t Thur\t Fri\t Set\t Sun\t')
	count = 0
	total_days = total_days_from_1990(year, month)
	# 在本月1号之前对应的星期输出制表符
	for i in range(total_days % 7):
		print(end = '\t')
		count += 1

	# 输出对应的日期
	for d in range(1, month_days(year, month) + 1):
		print(d, end='\t')
		count += 1
		if count % 7 == 0:
			print()
